<template>
	<view class="conter">
		<!-- <header-box :title="title" :childId="value"></header-box>  pages/shopping/stock   -->
		
		
		<view class="header" style="color: #000000;" @tap="goBack()">
			<view class="arrow">
			</view>
			<view class="title">
				{{title}}
			</view>
		</view>
		
		
		
		
		<view class="text-tab">
			<view class="box">
				<view class="marige-bor" v-for="(item, index) in textList" :key="index">
					<view class="diso-flex">
						<view class="">
							{{item.name}}
						</view>
						<view class="conter-image" @tap="skip(item)">
							<u-radio-group v-model="value" @change="radioGroupChange">
								<u-radio :name="item.id" active-color="#C0C2F9">
								</u-radio>
							</u-radio-group>

						</view>
					</view>
				</view>
			</view>
		</view>
		
		
		
		
		<navigator url="#" @click="showRemove1 = true" class="add">
			<image src="../../static/index/add.png" mode=""></image>
		</navigator>
		
		
		
		

		<view class="flex-box total">
			<view class="">
				合计：
			</view>
			<view class="">
				{{total}} 个
			</view>
		</view>


		<!-- 底部弹层 -->
		<u-popup v-model="redactShow" mode="bottom" width="100%" height="330rpx" border-radius="40">
			<view class="padd-text" v-for="(item, index) in list" :key="index" @click="elect(item, index)">
				<text :class="[index == tabText ? 'color-text' : 'none-color']">{{item.name}}</text>
			</view>
		</u-popup>



		<!-- 编辑 弹出框 -->
		<u-popup v-model="showRemove" mode="center" width="580rpx" height="170px" border-radius="10">
			<view class="tilte-text">更改 - {{stockName}}</view>
			<view class="" style="font-size: 28rpx; 
				color: #999999; 
				width: 480rpx;
				height: 70rpx; 
				background: #F5F5F5; 
				margin: 0 auto;
				border-radius: 20rpx;">
				<input type="text" style="background: #F5F5F5;
					width: 480rpx; height: 100%;
					padding-left: 10rpx;
					text-align: center;
					border-radius: 10rpx;"
				 v-model="val" placeholder="请输入仓库名" />
			</view>
			<view class="btn-bor">
				<text class="left-bor" @click="showRemove= false">取消</text>
				<text @click="removeText">确定</text>
			</view>
		</u-popup>


		<u-popup v-model="showRemove1" mode="center" width="580rpx" height="170px" border-radius="10">
			<view class="tilte-text">添加仓库</view>
			<view class="" style="font-size: 28rpx; 
				color: #999999; 
				width: 480rpx;
				height: 70rpx; 
				background: #F5F5F5; 
				margin: 0 auto;
				border-radius: 20rpx;">
				<input type="text" style="background: #F5F5F5;
					width: 480rpx; height: 100%;
					padding-left: 10rpx;
					text-align: center;
					border-radius: 10rpx;"
				 v-model="valName" placeholder="请输入仓库名" />
			</view>
			<view class="btn-bor">
				<text class="left-bor" @click="showRemove1 = false">取消</text>
				<text @click="addNmame">确定</text>
			</view>
		</u-popup>



		<u-popup v-model="showRemove2" mode="center" width="580rpx" height="170px" border-radius="10">
			<view class="tilte-text">删除</view>
			<view class="" style="font-size: 28rpx; 
				color: #999999; 
				width: 480rpx;
				height: 70rpx;
				 line-height: 70rpx;
				 text-align: center;
				background: #F5F5F5; 
				margin: 0 auto;
				border-radius: 20rpx;">
				{{stockName}}
			</view>
			<view class="btn-bor">
				<text class="left-bor" @click="showRemove2 = false">取消</text>
				<text @click="removeSrock">确定</text>
			</view>
		</u-popup>



	</view>
</template>

<script>
	import headerBox from '../../components/header/header.vue'

	export default {
		components: {
			headerBox
		},
		data() {
			return {
				title: '仓库',
				textList: [],
				redactShow: false,
				list: [{
					name: '编辑',
					show: true,
					url: ''
				}, {
					name: '删除',
					show: true
				}, {
					name: '取消',
					show: false
				}],
				showRemove: false,
				showRemove1: false,
				showRemove2: false,
				tabText: 0,
				total: 0,
				val: '',
				valName: '',
				stockName: '',
				stocId: '',
				value: 1,
				searchVal: '',
			}
		},
		onLoad() {
			this.stockList()
		},
		onShow() {

		},
		methods: {
			
			goBack() {
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				   let nowPage = pages[pages.length - 1]; //当前页页面实例
				   let prevPage = pages[pages.length - 2]
				 prevPage.$vm.searchVal = this.value; //修改上一页data里面的searchVal参数值为1211
				 prevPage.$vm.stockId = this.value; //修改上一页data里面的searchVal参数值为1211
				 prevPage.$vm.stockName = this.stockName; //修改上一页data里面的searchVal参数值为1211
				
				
				console.log(this.value)
				uni.navigateBack({
				    delta: 1
				})
			},
			

			radioGroupChange(e) {
				this.value = e
				console.log(e);
			},

			// 获取列表
			async stockList() {
				const res = await this.$u.post("api/jinxiao.Store/index");
				this.textList = res.data
				this.value = res.data[0].id
				this.stockName = res.data[0].name
				this.total = res.data.length
				
			},

			// 修改仓库名
			async removeText() {
				console.log('修改仓库名', this.val)
				if (!this.val) return this.$tools.msg('仓库名不能未空')
				const res = await this.$u.post("api/jinxiao.Store/edit?id=" + this.stocId + "&name=" + this.val, {});

				this.$tools.msg("修改成功");
				this.showRemove = false
				this.redactShow = false
				this.val = ''
				this.stockList()
				if (res.code !== 1) {
					this.$tools.msg("修改失败");
				}
			},

			// 添加仓库
			async addNmame() {
				if (!this.valName) return this.$tools.msg('名字不能为空')
				const res = await this.$u.post("api/jinxiao.Store/add?name=" + this.valName, {});
				this.$tools.msg(res.msg);
				this.showRemove1 = false
				this.redactShow = false
				this.valName = ''
				this.stockList()
				if (res.code !== 1) {
					this.$tools.msg("修改失败");
				}
			},

			// 删除仓库
			async removeSrock() {
				if (!this.stocId) return this.$tools.msg('请选择需要删除的仓库')
				const res = await this.$u.post("api/jinxiao.Store/delete?id=" + this.stocId, {});
				this.$tools.msg("删除成功");
				this.showRemove2 = false
				this.redactShow = false
				this.stockList()
				if (res.code !== 1) {
					this.$tools.msg("删除失败");
				}
			},

			skip(item) {
				this.stockName = item.name
				this.stocId = item.id
				// this.redactShow = true

			},

			elect(item, index) {
				console.log(index)
				this.tabText = index
				this.redactShow = item.show
				if (index == 0) {
					// 跳转到编辑页面
					this.showRemove = true
				} else if (index == 1) {
					// 调用删除事件
					this.showRemove2 = true
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.conter {
		width: 100%;
		height: 100%;
		position: relative;
		
		
		
		.header {
			width: 100%;
			height: 150rpx;
			line-height: 150rpx;
			display: flex;
			align-items: center;
			// padding-left: 10rpx;
			padding-top: 30rpx;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			background: linear-gradient(to right, #656CE6, #9397FC);
			
			.arrow{
			  position: relative;
			  display: inline-block;
			}
			
			.arrow::before{
			  content: '';
			  width: 10px;
			  height: 10px;
			  border: 0px;
			  border-bottom: solid 2px #fff;
			  border-left: solid 2px #fff;
			  -ms-transform: rotate(45deg);
			  -webkit-transform: rotate(45deg);
			  transform: rotate(45deg);
			  position: absolute;
			  top: 50%;
			  left: 0;
			  margin-top: -4px;
			  margin-left: 28rpx;
			}
			
			.title {
				color: #fff;
				margin: 0 auto;
			}
		}
		
		
		
		
		
		

		image {
			width: 100%;
			height: 100%;
		}

		.text-tab {
			padding: 30rpx;
			padding-bottom: 0;


			.box {
				width: 98%;
				margin: 0 auto;
				background-color: #FFFFFF;
				border-radius: 10rpx;

			}

			.marige-bor {
				color: #333333;
				display: flex;
				width: 90%;
				margin: 0 auto;
				font-size: 28rpx;
				// padding: 30rpx;
				align-items: center;
				border-bottom: 1rpx solid #F0F0F0;
				justify-content: space-between;

				.diso-flex {
					width: 100%;
					height: 80rpx;
					display: flex;
					align-items: center;
					font-size: 28rpx;
					justify-content: space-between;
				}

				.conter-image {
					width: 22rpx;
					height: 36rpx;
				}
			}

			.marige-bor:last-child {
				border-bottom: 0;
			}
		}

		.total {
			width: 100%;
			position: absolute;
			bottom: 0;
			left: 0;
			height: 100rpx;
			padding: 0 60rpx 0 30rpx;
			background-color: #FFFFFF;
		}


		.padd-text {
			width: 80%;
			height: 106rpx;
			line-height: 106rpx;
			text-align: center;
			font-size: 28rpx;
			color: #333;
			border-bottom: 1rpx solid #EEEEEE;
			margin: 0 auto;
		}

		.color-text {
			color: #7278EC;
		}

		.none-color {
			color: #000;
		}

		.padd-text:last-child {
			border-bottom: 0;
		}



		.tilte-text {
			color: #333;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			font-size: 32rpx;
		}
		
		// 加号
		.add {
			position: absolute;
			bottom: 200rpx;
			right: 40rpx;
			width: 140rpx;
			height: 140rpx;
			text-align: center;
			line-height: 100rpx;
			border-radius: 50%;
			font-size: 100rpx;
		}

		.btn-bor {
			width: 90%;
			height: 113rpx;
			color: #7278EC;
			margin: 0 auto;
			line-height: 113rpx;
			margin-top: 40rpx;
			display: flex;
			justify-content: space-around;
			border-top: 1rpx solid #EEEEEE;

			.left-bor {
				border-right: 1rpx solid #EEEEEE;
			}

			text {
				display: inline-block;
				width: 40%;
				height: 113rpx;
				text-align: center;
			}
		}
	}
</style>
